package com.example.padlock.view.service;

import java.util.List;

import android.os.Handler;
import android.support.v4.view.ViewPager;

import com.example.padlock.data.entity.AdResultEntity.AdEntity;

public class ScrollTask implements Runnable {

	private ViewPager viewPager;
	private List<AdEntity> imageViews;//滑动的图片集合
	private int currentItem = 0; //  当前图片的索引号


	/**
	 *  切换当前显示的图片
	 */
		private Handler handler = new Handler() {
			public void handleMessage(android.os.Message msg) {
				viewPager.setCurrentItem(currentItem);// 切换当前显示的图片
			};
		};
	public ScrollTask(ViewPager viewPager,List<AdEntity> picList){
		this.viewPager=viewPager;
		this.imageViews=picList;
	}
	@Override
	public void run() {

		synchronized (viewPager) {
			System.out.println("currentItem: " + currentItem);
			currentItem = (currentItem + 1) % imageViews.size();
			handler.obtainMessage().sendToTarget(); // 通过Handler切换图片
		}
	}

}
